<div class="problemindexholder" problemindex="B">
 <div class="ttypography">
  <div class="problem-statement">
   <div class="header">
    <div class="title">
     B. Diverging Directions
    </div>
    <div class="time-limit">
     <div class="property-title">
      time limit per test
     </div>
     3 seconds
    </div>
    <div class="memory-limit">
     <div class="property-title">
      memory limit per test
     </div>
     256 megabytes
    </div>
    <div class="input-file">
     <div class="property-title">
      input
     </div>
     standard input
    </div>
    <div class="output-file">
     <div class="property-title">
      output
     </div>
     standard output
    </div>
   </div>
   <div>
    <p>
     You are given a directed weighted graph with
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     nodes and
     <span class="tex-span">
      2
      <i>
       n
      </i>
      - 2
     </span>
     edges. The nodes are labeled from
     <span class="tex-span">
      1
     </span>
     to
     <span class="tex-span">
      <i>
       n
      </i>
     </span>
     , while the edges are labeled from
     <span class="tex-span">
      1
     </span>
     to
     <span class="tex-span">
      2
      <i>
       n
      </i>
      - 2
     </span>
     . The graph's edges can be split into two parts.
    </p>
    <ul>
     <li>
      The first
      <span class="tex-span">
       <i>
        n
       </i>
       - 1
      </span>
      edges will form a rooted spanning tree, with node
      <span class="tex-span">
       1
      </span>
      as the root. All these edges will point away from the root.
     </li>
     <li>
      The last
      <span class="tex-span">
       <i>
        n
       </i>
       - 1
      </span>
      edges will be from node
      <span class="tex-span">
       <i>
        i
       </i>
      </span>
      to node
      <span class="tex-span">
       1
      </span>
      , for all
      <span class="tex-span">
       2 ≤
       <i>
        i
       </i>
       ≤
       <i>
        n
       </i>
      </span>
      .
     </li>
    </ul>
    <p>
     You are given
     <span class="tex-span">
      <i>
       q
      </i>
     </span>
     queries. There are two types of queries
    </p>
    <ul>
     <li>
      <span class="tex-span">
       1
       <i>
        i
       </i>
       <i>
        w
       </i>
      </span>
      : Change the weight of the
      <span class="tex-span">
       <i>
        i
       </i>
      </span>
      -th edge to
      <span class="tex-span">
       <i>
        w
       </i>
      </span>
     </li>
     <li>
      <span class="tex-span">
       2
       <i>
        u
       </i>
       <i>
        v
       </i>
      </span>
      : Print the length of the shortest path between nodes
      <span class="tex-span">
       <i>
        u
       </i>
      </span>
      to
      <span class="tex-span">
       <i>
        v
       </i>
      </span>
     </li>
    </ul>
    <p>
     Given these queries, print the shortest path lengths.
    </p>
   </div>
   <div class="input-specification">
    <div class="section-title">
     Input
    </div>
    <p>
     The first line of input will contain two integers
     <span class="tex-span">
      <i>
       n
      </i>
      ,
      <i>
       q
      </i>
     </span>
     (
     <span class="tex-span">
      2 ≤
      <i>
       n
      </i>
      ,
      <i>
       q
      </i>
      ≤ 200 000
     </span>
     ), the number of nodes, and the number of queries, respectively.
    </p>
    <p>
     The next
     <span class="tex-span">
      2
      <i>
       n
      </i>
      - 2
     </span>
     integers will contain 3 integers
     <span class="tex-span">
      <i>
       a
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
      ,
      <i>
       b
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
      ,
      <i>
       c
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
     </span>
     , denoting a directed edge from node
     <span class="tex-span">
      <i>
       a
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
     </span>
     to node
     <span class="tex-span">
      <i>
       b
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
     </span>
     with weight
     <span class="tex-span">
      <i>
       c
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
     </span>
     .
    </p>
    <p>
     The first
     <span class="tex-span">
      <i>
       n
      </i>
      - 1
     </span>
     of these lines will describe a rooted spanning tree pointing away from node
     <span class="tex-span">
      1
     </span>
     , while the last
     <span class="tex-span">
      <i>
       n
      </i>
      - 1
     </span>
     of these lines will have
     <span class="tex-span">
      <i>
       b
      </i>
      <sub class="lower-index">
       <i>
        i
       </i>
      </sub>
      = 1
     </span>
     .
    </p>
    <p>
     More specifically,
    </p>
    <ul>
     <li>
      The edges
      <span class="tex-span">
       (
       <i>
        a
       </i>
       <sub class="lower-index">
        1
       </sub>
       ,
       <i>
        b
       </i>
       <sub class="lower-index">
        1
       </sub>
       ), (
       <i>
        a
       </i>
       <sub class="lower-index">
        2
       </sub>
       ,
       <i>
        b
       </i>
       <sub class="lower-index">
        2
       </sub>
       ), ... (
       <i>
        a
       </i>
       <sub class="lower-index">
        <i>
         n
        </i>
        - 1
       </sub>
       ,
       <i>
        b
       </i>
       <sub class="lower-index">
        <i>
         n
        </i>
        - 1
       </sub>
       )
      </span>
      will describe a rooted spanning tree pointing away from node
      <span class="tex-span">
       1
      </span>
      .
     </li>
     <li>
      <span class="tex-span">
       <i>
        b
       </i>
       <sub class="lower-index">
        <i>
         j
        </i>
       </sub>
       = 1
      </span>
      for
      <span class="tex-span">
       <i>
        n
       </i>
       ≤
       <i>
        j
       </i>
       ≤ 2
       <i>
        n
       </i>
       - 2
      </span>
      .
     </li>
     <li>
      <span class="tex-span">
       <i>
        a
       </i>
       <sub class="lower-index">
        <i>
         n
        </i>
       </sub>
       ,
       <i>
        a
       </i>
       <sub class="lower-index">
        <i>
         n
        </i>
        + 1
       </sub>
       , ...,
       <i>
        a
       </i>
       <sub class="lower-index">
        2
        <i>
         n
        </i>
        - 2
       </sub>
      </span>
      will be distinct and between
      <span class="tex-span">
       2
      </span>
      and
      <span class="tex-span">
       <i>
        n
       </i>
      </span>
      .
     </li>
    </ul>
    <p>
     The next
     <span class="tex-span">
      <i>
       q
      </i>
     </span>
     lines will contain 3 integers, describing a query in the format described in the statement.
    </p>
    <p>
     All edge weights will be between
     <span class="tex-span">
      1
     </span>
     and
     <span class="tex-span">
      10
      <sup class="upper-index">
       6
      </sup>
     </span>
     .
    </p>
   </div>
   <div class="output-specification">
    <div class="section-title">
     Output
    </div>
    <p>
     For each type 2 query, print the length of the shortest path in its own line.
    </p>
   </div>
   <div class="sample-tests">
    <div class="section-title">
     Example
    </div>
    <div class="sample-test">
     <div class="input">
      <div class="title">
       Input
      </div>
      <pre>5 9<br/>1 3 1<br/>3 2 2<br/>1 4 3<br/>3 5 4<br/>5 1 5<br/>3 1 6<br/>2 1 7<br/>4 1 8<br/>2 1 1<br/>2 1 3<br/>2 3 5<br/>2 5 2<br/>1 1 100<br/>2 1 3<br/>1 8 30<br/>2 4 2<br/>2 2 4<br/></pre>
     </div>
     <div class="output">
      <div class="title">
       Output
      </div>
      <pre>0<br/>1<br/>4<br/>8<br/>100<br/>132<br/>10<br/></pre>
     </div>
    </div>
   </div>
  </div>
  <p>
  </p>
 </div>
</div>
